﻿using UnityEngine;
using System.Collections.Generic;


namespace UI
{
    public class UILuckTemplate : MonoBehaviour
    {
        #region 模版
        public GameObject template;
        #endregion

        protected UIHeroLuck luck;
        public bool center;
        /// <summary>
        /// Init
        /// </summary>
        /// <param name="ids">"hero_001;hero_002;hero_003"</param>
        public void Init(UIHeroLuck luck)
        {
            this.luck = luck;
            DictData();
            SetIcon();
            Center();

            InitActived();
            InitMasked();
        }
        
        /// <summary>
        /// 查字典数据
        /// </summary>
        public virtual void DictData()
        {
        }

        protected virtual void Center()
        {
            center = false;
        }
        
        /// <summary>
        /// 激活
        /// </summary>
        protected virtual void Actived(bool yes0,bool yes1=false,bool yes2 = false)
        {
            
        }

        /// <summary>
        /// 拥有
        /// </summary>
        protected virtual void Masked(bool yes0, bool yes1 = false, bool yes2 = false)
        {

        }


        public void SetMasked(List<bool> maskeds)
        {
            if (maskeds.Count == 0) Masked(false);
            if (maskeds.Count == 1) Masked(maskeds[0]);
            if (maskeds.Count == 2) Masked(maskeds[0], maskeds[1]);
            if (maskeds.Count == 3) Masked(maskeds[0], maskeds[1], maskeds[2]);
        }

        public void SetActived(List<bool> activeds)
        {
            if (activeds.Count == 0) Actived(false);
            if (activeds.Count == 1) Actived(activeds[0]);
            if (activeds.Count == 2) Actived(activeds[0], activeds[1]);
            if (activeds.Count == 3) Actived(activeds[0], activeds[1], activeds[2]);
        }

        /// <summary>
        /// 点击行为
        /// </summary>
        public virtual void OnClick()
        {

        }

        /// <summary>
        /// 设置图标
        /// </summary>
        public virtual void SetIcon(){}

        protected virtual void MainTexture(UITexture tex,string iconName)
        {
        }

        public virtual void InitActived()
        {
            if (!center)
            {
                luck.FreshLuckActived();
                if (luck.IsActived)
                {
                    if (luck.luckType == Story.LuckType.Hero)
                    {
                        List<bool> actived = new List<bool>();
                        if (!string.IsNullOrEmpty(luck.luckData.hero0)) actived.Add(true);
                        if (!string.IsNullOrEmpty(luck.luckData.hero1)) actived.Add(true);
                        if (!string.IsNullOrEmpty(luck.luckData.hero2)) actived.Add(true);
                        if (!string.IsNullOrEmpty(luck.luckData.hero3)) actived.Add(true);

                        SetActived(actived);
                    }
                    else if(luck.luckType == Story.LuckType.Equipment || 
                        luck.luckType == Story.LuckType.Treasure)
                    {
                        List<bool> actived = new List<bool>();
                        actived.Add(true);
                        SetActived(actived);
                    }
                }
                else
                {
                    if (luck.luckType == Story.LuckType.Hero)
                    {
                        List<bool> actived = new List<bool>();
                        if (!string.IsNullOrEmpty(luck.luckData.hero0)) actived.Add(false);
                        if (!string.IsNullOrEmpty(luck.luckData.hero1)) actived.Add(false);
                        if (!string.IsNullOrEmpty(luck.luckData.hero2)) actived.Add(false);
                        if (!string.IsNullOrEmpty(luck.luckData.hero3)) actived.Add(false);

                        SetActived(actived);
                    }
                    else if(luck.luckType == Story.LuckType.Equipment ||
                        luck.luckType == Story.LuckType.Treasure)
                    {
                        List<bool> actived = new List<bool>();
                        actived.Add(false);
                        SetActived(actived);
                    }

                }
            }
        }

        public virtual void InitMasked()
        {
           
        }

    }
}